package mymyoux.utils
{
	public class Iterator
	{
		protected var _index:uint=0;
		protected var _argsName:Array;
		protected var _argsValue:Array;
		public function Iterator(...args)
		{
			_argsName=new Array();
			_argsValue=new Array();
			for(var i:uint=1;i<args.length;i+=2){
				this.add(args[i-1].toString(),args[i]);
			}
		}
		public function add(key:String,value:*):uint{
			if(key.length>0){
				_argsName.push(key);
				_argsValue.push(value);
			}
			return length;
		}
		public function rem():void{
			if(_argsName.length>_index){
				_argsName.splice(_index,1);
				_argsValue.splice(_index,1);
				_index=Math.max(_index-1,0);
			}
		}
		public function hasNext():Boolean{
			return _argsName.length>_index+1;
		}
		public function next():void{
			if(hasNext()){
				_index++;
			}
		}
		public function reset():void{
			_index=0;
		}
		public function size():uint{
			return _argsName.length;
		}
		public function get key():String{
			return _argsName[_index];
		}
		public function get value():*{
			return _argsValue[_index];
		}
		public function get length():uint{
			return size();
		}
		public function toString():String{
			var result:String="[Iterator ";
			for(var i:uint=0;i<_argsName.length;i++){
				result+=_argsName[i]+"=\""+_argsValue[i]+"\" ";
			}
			return result.substring(0,result.length-1)+"]";
		}
	}
}